{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}E:\Github\Bolivia\00_replication_files\log-files/2_Figure_3.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}25 Jan 2022, 21:39:40
{txt}
{com}. 
. timer on 2
{txt}
{com}. 
. *----------*
. * Figure 3 *
. *----------*
.         * Figure 3a
.         *----------
.                 * Loading our computo data, with the numeric date. 
.                 * Then we create the string date from the numeric date                 
.                 import excel using "data/inputs/1_Bolivia_data_computo.xlsx", ///
>                         clear first sheet("2.RecepcionSobres")
{res}{txt}
{com}. 
.                 keep if ElecActa == "Presidente y Vicepresidente"
{txt}(33,585 observations deleted)

{com}. 
.                 keep Pais - NumMesa CC - Nulos ComputoDate
{txt}
{com}.                 drop ValidosenActa
{txt}
{com}. 
.                 gen hour = hh(ComputoDate)
{txt}
{com}.                 gen minute = mm(ComputoDate)
{txt}
{com}.                 gen second = ss(ComputoDate)
{txt}
{com}.                 replace second = floor(second)
{txt}(10,902 real changes made)

{com}. 
.                 gen date = dofc(ComputoDate)
{txt}
{com}.                 format date %td
{txt}
{com}.                 gen day = day(date)
{txt}
{com}.                 gen month = month(date)
{txt}
{com}.                 gen year = year(date)
{txt}
{com}. 
.                 replace minute = minute + 1 if second > 30
{txt}(10,902 real changes made)

{com}.                 replace hour = hour + 1 if minute == 60
{txt}(194 real changes made)

{com}.                 replace minute = 0 if minute == 60
{txt}(194 real changes made)

{com}. 
.                 gen ampm = ""
{txt}(34,555 missing values generated)

{com}.                 replace ampm = "a.m." if hour < 12
{txt}variable {bf}ampm{sf} was {bf}{res}str1{sf}{txt} now {bf}{res}str4{sf}
{txt}(12,975 real changes made)

{com}.                 replace ampm = "p.m." if hour >= 12
{txt}(21,580 real changes made)

{com}.                 replace hour = 12 if hour == 0
{txt}(2,105 real changes made)

{com}.                 replace hour = hour - 12 if ampm == "p.m." & hour != 12
{txt}(19,139 real changes made)

{com}. 
.                 tostring hour minute second day month year, replace
{txt}hour was {res:float} now {res:str2}
minute was {res:float} now {res:str2}
second was {res:float} now {res:str2}
day was {res:float} now {res:str2}
month was {res:float} now {res:str2}
year was {res:float} now {res:str4}

{com}.                 replace minute = "0" + minute if length(minute) == 1
{txt}(5,760 real changes made)

{com}.                 replace hour = "0" + hour if length(hour) == 1
{txt}(21,567 real changes made)

{com}. 
.                 gen ComputoDate_string = day + "/" + month + "/" + year + " " + ///
>                         hour + ":" + minute + " " + ampm
{txt}
{com}.                 drop hour minute second date day month year ampm
{txt}
{com}. 
.                 foreach x of varlist CC-Nulos {c -(}
{txt}  2{com}.                         destring `x', force replace
{txt}  3{com}.                         replace `x' = 0 if `x' == .
{txt}  4{com}.                 {c )-}
{txt}CC already numeric; no {res}replace
{txt}(556 real changes made)
FPV already numeric; no {res}replace
{txt}(19,341 real changes made)
MTS already numeric; no {res}replace
{txt}(13,725 real changes made)
UCS already numeric; no {res}replace
{txt}(18,101 real changes made)
MAS already numeric; no {res}replace
{txt}(13 real changes made)
F already numeric; no {res}replace
{txt}(3,694 real changes made)
PDC already numeric; no {res}replace
{txt}(676 real changes made)
MNR already numeric; no {res}replace
{txt}(16,485 real changes made)
PANBOL already numeric; no {res}replace
{txt}(14,322 real changes made)
Blancos already numeric; no {res}replace
{txt}(7,377 real changes made)
Nulos already numeric; no {res}replace
{txt}(942 real changes made)

{com}. 
.                 * Generating the MAS vote share and the pcs variable WITH THE STRING DATE
.                 * Measures that DO USE Blancos and Nulos (sorted)
.                 gen total_so = CC + FPV + MTS + UCS + MAS + F + PDC + MNR + PANBOL + ///
>                         Blancos + Nulos
{txt}
{com}.                 *---*
.                 gen mshare_so = MAS / total_so
{txt}(4 missing values generated)

{com}.                 gen cshare_so = CC / total_so
{txt}(4 missing values generated)

{com}.                 gen x = runiform()
{txt}
{com}.                 sort ComputoDate_string x
{txt}
{com}.                 gen cumsumtotal_so = sum(total_so)
{txt}
{com}.                 *---*
.                 egen maxcumsumtotal_so = max(cumsumtotal_so)
{txt}
{com}.                 gen pcs_so = cumsumtotal_so / maxcumsumtotal_so
{txt}
{com}.                 drop cumsumtotal_so maxcumsumtotal_so total_so
{txt}
{com}. 
.                 replace mshare_so = mshare_so * 100
{txt}(34,542 real changes made)

{com}. 
.                 twoway (lowess mshare_so pcs_so if pcs_so < 0.95, lcolor(midblue) ///
>                                 lwidth(thick) sort mean bwidth(0.3)) ///
>                         (lowess mshare_so pcs_so if pcs_so >= 0.95, lcolor(midblue) ///
>                                 lwidth(thick) sort mean bwidth(0.6)), ///
>                         ylabel(0(0.20)1) xline(0.95, lcolor(black)) yline(50, ///
>                                 lcolor(black)) xlabel(0.95) ///
>                         graphregion(color(white)) legend(off) ///
>                         ylabel(0 20 40 60 80 100, angle(0)) ///
>                         xtitle("Proportion of Votes Counted in Definitive Results System") ///
>                         ytitle("Polling Station Level MAS Vote Share")
{res}{txt}
{com}.                 graph export "outputs/generated/Figure_3a.pdf", replace
{txt}(file outputs/generated/Figure_3a.pdf written in PDF format)

{com}. 
.         * Figure 3b
.         *----------
.                 * Now we regenerate the % counted using the correct chronological date
.                 drop pcs_so ComputoDate_string mshare_so cshare_so x //Just to avoid mistakes
{txt}
{com}. 
.                 * Measures that DO USE Blancos and Nulos (sorted)
.                 *---*
.                 gen total_so = CC + FPV + MTS + UCS + MAS + F + PDC + MNR + PANBOL + ///
>                         Blancos + Nulos
{txt}
{com}.                 *---*
.                 gen mshare_so = MAS / total_so
{txt}(4 missing values generated)

{com}.                 gen cshare_so = CC / total_so
{txt}(4 missing values generated)

{com}.                 gen x = runiform()
{txt}
{com}.                 sort ComputoDate x
{txt}
{com}.                 gen cumsumtotal_so = sum(total_so)
{txt}
{com}.                 *---*
.                 egen maxcumsumtotal_so = max(cumsumtotal_so)
{txt}
{com}.                 gen pcs_so = cumsumtotal_so / maxcumsumtotal_so
{txt}
{com}.                 drop cumsumtotal_so maxcumsumtotal_so total_so
{txt}
{com}. 
.                 replace mshare_so = mshare_so * 100
{txt}(34,542 real changes made)

{com}. 
.                 twoway (lowess mshare_so pcs_so if pcs_so < 0.95, lcolor(midblue) ///
>                                 lwidth(thick) sort mean bwidth(0.3)) ///
>                         (lowess mshare_so pcs_so if pcs_so >= 0.95, lcolor(midblue) ///
>                                 lwidth(thick) sort mean bwidth(0.6)), ///
>                         ylabel(0(0.20)1) xline(0.95, lcolor(black)) yline(50, ///
>                                 lcolor(black)) xlabel(0.95) ///
>                         graphregion(color(white)) legend(off) ///
>                         ylabel(0 20 40 60 80 100, angle(0)) ///
>                         xtitle("Proportion of Votes Counted in Definitive Results System") ///
>                         ytitle("Polling Station Level MAS Vote Share")
{res}{txt}
{com}.                 graph export "outputs/generated/Figure_3b.pdf", replace
{txt}(file outputs/generated/Figure_3b.pdf written in PDF format)

{com}. 
. *------------------------------------------------------------------------------*
. timer off 2
{txt}
{com}. timer list 2
{res}   2:     17.96 /        1 =      17.9570
{txt}
{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}E:\Github\Bolivia\00_replication_files\log-files/2_Figure_3.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}25 Jan 2022, 21:39:58
{txt}{.-}
{smcl}
{txt}{sf}{ul off}